package com.stylefeng.guns.biz.hot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.biz.banner.model.TBanner;
import com.stylefeng.guns.biz.hot.model.HotList;
import com.stylefeng.guns.biz.hot.service.IHotListService;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-07-30 03:15:16
 */
@Controller
@RequestMapping("/hotList")
public class HotListController extends BaseController {

    private String PREFIX = "/app/hotList/";

    @Autowired
    private IHotListService hotListService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "hotList.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/hotList_add")
    public String hotListAdd() {
        return PREFIX + "hotList_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/hotList_update/{hotListId}")
    public String hotListUpdate(@PathVariable Integer hotListId, Model model) {
        HotList hotList = hotListService.selectById(hotListId);
        model.addAttribute("item",hotList);
        LogObjectHolder.me().set(hotList);
        return PREFIX + "hotList_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String appid) {
    	
    	EntityWrapper<HotList> wrapper=new EntityWrapper<>();
    	wrapper.eq("app_id_key", appid);
    	
        return hotListService.selectList(wrapper);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(HotList hotList) {
        hotListService.insert(hotList);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer hotListId) {
        hotListService.deleteById(Long.valueOf(hotListId));
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(HotList hotList) {
        hotListService.updateById(hotList);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{hotListId}")
    @ResponseBody
    public Object detail(@PathVariable("hotListId") Integer hotListId) {
        return hotListService.selectById(hotListId);
    }
}
